package com.codeczx.pattledemo;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
import android.util.Log;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.imageView1)
    ImageView imageView1;
    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.textView3)
    TextView textView3;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.textView4)
    TextView textView4;
    @BindView(R.id.imageView4)
    ImageView imageView4;
    @BindView(R.id.textView5)
    TextView textView5;
    @BindView(R.id.imageView5)
    ImageView imageView5;
    @BindView(R.id.textView6)
    TextView textView6;
    @BindView(R.id.imageView6)
    ImageView imageView6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.head);
        Palette.Builder builder = new Palette.Builder(bitmap);
        builder.generate(new Palette.PaletteAsyncListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onGenerated(Palette palette) {
                Palette.Swatch getVibrantSwatch = palette.getVibrantSwatch();
                Palette.Swatch getDarkVibrantSwatch = palette.getDarkVibrantSwatch();
                Palette.Swatch getLightVibrantSwatch = palette.getLightVibrantSwatch();
                Palette.Swatch getMutedSwatch = palette.getMutedSwatch();
                Palette.Swatch getDarkMutedSwatch = palette.getDarkMutedSwatch();
                Palette.Swatch getLightMutedSwatch = palette.getLightMutedSwatch();


                if (getVibrantSwatch != null) {
                    imageView1.setImageDrawable(new ColorDrawable(getVibrantSwatch.getRgb()));
                }
                if (getDarkVibrantSwatch != null) {
                    imageView2.setImageDrawable(new ColorDrawable(getDarkVibrantSwatch.getRgb()));
                }
                if (getLightVibrantSwatch != null) {
                    imageView3.setImageDrawable(new ColorDrawable(getLightVibrantSwatch.getRgb()));
                }
                if (getMutedSwatch != null) {
                    imageView4.setImageDrawable(new ColorDrawable(getMutedSwatch.getRgb()));
                }
                if (getDarkMutedSwatch != null) {
                    imageView5.setImageDrawable(new ColorDrawable(getDarkMutedSwatch.getRgb()));
                }
                if (getLightMutedSwatch != null) {
                    imageView6.setImageDrawable(new ColorDrawable(getLightMutedSwatch.getRgb()));
                }

//                Window window = getWindow();
//                window.setStatusBarColor(getDarkVibrantSwatch.getRgb());
//                getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getLightVibrantSwatch.getRgb()));
            }
        });
    }
}
